package net.towee.model.repo.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.towee.model.bittorrent.TorrentData;
import net.towee.model.bittorrent.TorrentItem;
import net.towee.model.discussion.Discussion;
import net.towee.model.repo.AttachmentIdentity;
import net.towee.model.repo.AttachmentInfo;
import net.towee.model.repo.AttachmentPicture;
import net.towee.model.repo.AttachmentTorrent;
import net.towee.server.persistence.impl.MongoDbStore;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Reference;

/**
 * Attachment information stored in document
 * @author c58
 */
@Entity(MongoDbStore.ATTACH_INFO_COLLECTION)
public class AttachmentInfoImpl implements AttachmentInfo, AttachmentPicture, AttachmentTorrent {
	@Id private String id;
	// General
	@Reference protected AttachmentIdentity identity;
	protected Discussion discussion;
	
	// Picture
	private Date creationDate;
	private int width;
	private int height;
	private int iso;
	private String camera;
	private String exposure;
	private String diaphragm;
	private String fnum;
	private boolean flash;

	// Torrent
	@Reference private TorrentData torrent;
	private List<TorrentItem> items;

	public AttachmentInfoImpl() {}
	public AttachmentInfoImpl(AttachmentIdentity id, Discussion discussion) {
		this.id = id.getId();
		this.identity = id;
		this.discussion = discussion;
		this.items = new ArrayList<TorrentItem>();
	}
	
	@Override
	public AttachmentIdentity getIdentity() {
		return identity;
	}

	@Override
	public Discussion getDiscussion() {
		return discussion;
	}
	
	/**
	 * TORRENT
	 */
	@Override
	public void setTorrentData(TorrentData torr) {
		this.torrent = torr;
	}
	@Override
	public void setItemsList(List<TorrentItem> list) {
		this.items = list;
	}
	@Override
	public List<TorrentItem> getItemsList() {
		return items;
	}
	@Override
	public int getSeeds() {
		return torrent.getSeeders();
	}
	@Override
	public int getPeers() {
		return torrent.getPeersList().size();
	}
	@Override
	public String getInfoHash() {
		return torrent.getInfoHash();
	}

	/**
	 * PICTURE
	 */
	/*
	 * Setters
	 */
	public void setFlash(boolean f){
		this.flash = f;
	}
	public void setFocus(String fnum) {
		this.fnum = fnum;
	}
	public void setDiaphragm(String d) {
		this.diaphragm = d;
	}
	public void setExposure(String ex) {
		this.exposure = ex;
	}
	public void setCamera(String c) {
		this.camera = c;
	}
	public void setISO(int iso) {
		this.iso = iso;
	}
	public void setHeight(int h) {
		this.height = h;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public void setCreationDate(Date date) {
		this.creationDate = date;
	}
	
	/*
	 * Getters
	 */
	@Override
	public Date getCreationDate() {
		return creationDate;
	}

	@Override
	public int getWidth() {
		return width;
	}

	@Override
	public int getHeight() {
		return height;
	}

	@Override
	public int geISO() {
		return iso;
	}

	@Override
	public String getCamera() {
		return camera;
	}

	@Override
	public String getExposure() {
		return exposure;
	}

	@Override
	public String getDiaphragm() {
		return diaphragm;
	}

	@Override
	public String getFocus() {
		return fnum;
	}

	@Override
	public boolean getFlash() {
		return flash;
	}
	
	/**
	 * Helpers
	 */
	@Override
	public AttachmentPicture toPicture() {
		return this;
	}
	@Override
	public AttachmentTorrent toTorrent() {
		return this;
	}
}
